package com.eboss.sbs.activity;

import android.os.Bundle;
import android.view.View;

import com.eboss.sbs.R;
import com.eboss.sbs.activity.base.BaseActivity;
import com.eboss.sbs.http.API;
import com.eboss.sbs.http.HttpCallback;
import com.eboss.sbs.model.MessageDetailEntity;
import com.google.gson.reflect.TypeToken;
import com.mytools.tool.utils.TimeUtil;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class MessageDetailActivity extends BaseActivity {

	public static String MSG_ID = "MSG_ID";
	
	private int msgId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		mActivity = this;
		setContentView(R.layout.activity_message_detail);
		super.onCreate(savedInstanceState);
		initView();
	}
	
	private void initView(){
		showView(R.id.titleback_btn_back, true);
		setTvText(R.id.tv_title, "消息详情 ");
		
		findViewById(R.id.titleback_btn_back).setOnClickListener(this);
		
		msgId = getIntent().getIntExtra(MSG_ID, -1);
		
		getdata();
		
	}
	
	private void getdata(){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sid", mApp.getLoginEntity().getSid());
		params.put("msgId", msgId);
		
		API.http_post(this, API.MESSAGE_DETAIL, params, new HttpCallback<MessageDetailEntity>(this) {
			@Override
			public void onSuccess(int statusCode, MessageDetailEntity data) {
				if(data!=null){
					setTvText(R.id.tv_msg_title, data.getTitle()); 
					setTvText(R.id.tv_time, TimeUtil.getStringFromDate(new Date(data.getTime()), "yyyy年MM月dd日 HH:mm:ss"));
					setTvText(R.id.tv_content, data.getContent()); 
				}
			}
			
			@SuppressWarnings({ "unchecked", "rawtypes" })
			@Override
			public TypeToken getTypeToken() {
				return new TypeToken<MessageDetailEntity>() {
				};
			}
		});
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.titleback_btn_back:
				finish();
				break;
	
			default:break;
		}
		super.onClick(v);
	}
	
}
